package com.quanfu.dao.impl;

import com.quanfu.dao.StudentDao;
import com.quanfu.pojo.Student;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class StudentDaoImpl implements StudentDao {
    // 直接问ioc伸手要
    private JdbcTemplate jdbcTemplate;

    // 注入我们的jdbcTemplate对象
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public List<Student> queryAll() {
        // jdbcTemplate进行数据库的查询 ioc容器进行装配，不要自己去实例化

        String sql = "select id, name, gender, age, class as classes from students";
        List<Student> students = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Student.class));

        System.out.println("studentDao" + students);


        return students;
    }
}
